package com.example.tbsdemo;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.text.TextUtils;
import android.widget.Toast;

import java.io.File;

public class TBSActivity extends AppCompatActivity {
    String url;
    SuperFileView2 mSuperFileView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tbs);
         url = getIntent().getType();
        if (TextUtils.isEmpty(url)){
            Toast.makeText(this, "输入的地址为空！！", Toast.LENGTH_SHORT).show();
            return;
        }
    init();
    }

    public void init(){//初始化SuperFileView2
        mSuperFileView =  findViewById(R.id.mSuperFileView);
        mSuperFileView.setOnGetFilePathListener(new SuperFileView2.OnGetFilePathListener() {
            @Override
            public void onGetFilePath(SuperFileView2 mSuperFileView2) {//mSuperFileView.show();之后回调这里
                downfile(mSuperFileView2);
            }
        });

        mSuperFileView.show();
    }
    public void downfile(final SuperFileView2 superFileView2){//下载office文件并且丢进SuperFileView2中显示
        DownLoadUtils.downLoadDatabase(url, new DownLoadUtils.CallBack() {
            @Override
            public void FileCallBack(File file) {
                superFileView2.displayFile(file);
            }
        });

    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mSuperFileView != null)
            mSuperFileView.onStopDisplay();
    }
}
